Imports System.Data
Imports System.Data.SqlClient
Imports ENTIDADES
Imports System.Collections.Generic




Public Class Localidades
    Public Function GetALL() As List(Of ENTIDADES.Localidad)


        Using oCnn As SqlConnection = CreateConnection()

            oCnn.Open()
            Using oCmd As New SqlCommand
                oCmd.Connection = oCnn
                oCmd.CommandType = CommandType.StoredProcedure
                oCmd.CommandText = "localidadesGetAll"
                Dim olocalidades As New List(Of ENTIDADES.Localidad)

                Try
                    Using oReader As SqlClient.SqlDataReader = oCmd.ExecuteReader
                        Do While oReader.Read
                            Dim olocalidad As New ENTIDADES.Localidad
                            olocalidad.id = Convert.ToInt32(oReader("idlocalidad"))
                            olocalidad.lugar = oReader("nombre").ToString
                            olocalidad.codpostal = oReader("codigopostal").ToString
                            olocalidades.Add(olocalidad)
                            olocalidad = Nothing
                        Loop
                        Return olocalidades
                    End Using
                Finally
                    olocalidades = Nothing
                End Try
            End Using
        End Using
    End Function
    Public Function GetOne(ByVal Id As Int32) As List(Of ENTIDADES.Localidad)


        Using oCnn As SqlConnection = CreateConnection()

            oCnn.Open()
            Using oCmd As New SqlCommand
                oCmd.Connection = oCnn
                oCmd.CommandType = CommandType.StoredProcedure
                oCmd.CommandText = "LocalidadesGetOne"
                oCmd.Parameters.AddWithValue("@idlocalidad", Id)
                Dim olocalidades As New List(Of ENTIDADES.Localidad)

                Try
                    Using oReader As SqlClient.SqlDataReader = oCmd.ExecuteReader
                        Do While oReader.Read
                            Dim olocal As New ENTIDADES.Localidad
                            olocal.id = Convert.ToInt32(oReader("idlocalidad"))

                            olocal.lugar = oReader("nombre").ToString

                            olocal.codpostal = oReader("codigopostal").ToString

                            olocalidades.Add(olocal)
                            olocal = Nothing
                        Loop
                        Return olocalidades
                    End Using
                Finally
                    olocalidades = Nothing
                End Try
            End Using
        End Using
    End Function
End Class
